1 /*
2 * decode the URL. Borrowed code.
3 */
4
5 import java.net.*;
6 import java.io.*;
7
8 class URLDecoder {
9 private URLDecoder() {}
10
11 public static String decode(String s) {
12 ByteArrayOutputStream out = new ByteArrayOutputStream(s.length());
13 for (int count = 0; count < s.length(); count++) {
14 if(s.charAt(count) == '%') {
15 count++;
16 int a = Character.digit(s.charAt(count++),16);
17 a = a<<4;
18 int b = Character.digit(s.charAt(count),16);
19 out.write(a+b);
20 } else {
21 if (s.charAt(count) == '+') {
22 out.write(' ');
23 } else {
24 out.write(s.charAt(count));
25 }
26 }
27 }
28
29 return (out.toString());
30 }
31 }
32
33
|